<!DOCTYPE html>
<html>
<head>
	<title>引流宝 - 安装环境检测</title>
	<meta charset="utf-8">
	<link rel="stylesheet" href="install.css">
	<link rel="shortcut icon" href="../../static/img/favicon.png">
</head>
<body>
    <div id="app">
        <div class="container" style="margin-top: 100px;">
            <div class="logo"></div>
            <table class="table">
                <thead>
                    <tr>
                        <th>安装环境</th>
                        <th>环境要求</th>
                        <th>当前情况</th>
                        <th>检测结果</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>PHP版本</td>
                        <td>PHP 7.0 - 7.4</td>
                        <td class="td1"> - </td>
                        <td class="td2"> - </td>
                    </tr>
                    <tr>
                        <td>上传权限</td>
                        <td>允许上传文件</td>
                        <td class="td3"> - </td>
                        <td class="td4"> - </td>
                    </tr>
                </tbody>
            </table>
            <span class="button_view"></span>
        </div>
        
        <div class="container">
            <p class="update">版本升级</p>
            <table class="table">
                <thead>
                    <tr>
                        <th>最低版本要求</th>
                        <th>升级版本</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>2.3.0</td>
                        <td>2.4.0</td>
                        <td><a href="2.4.0">立即升级</a></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    
    <script>
    
        // 检测脚本
        fetch('installCheck.php')
        .then(response => {
            return response.json();
        })
        .then(res => {
            
            // 检测结果
            if(res.code == 200) {
                document.querySelector('.td1').innerHTML = res.php_version;
                document.querySelector('.td2').innerHTML = res.php_version_result_text;
                document.querySelector('.td3').innerHTML = res.upload_result;
                document.querySelector('.td4').innerHTML = res.upload_result_text;
                
                // 所有符合才可进行安装
                if(res.php_version >= '7.0' && res.php_version <= '7.5' && res.upload_result == '获得上传权限') {
                    const buttonView = document.querySelector('.button_view');
                    buttonView.innerHTML = '<button class="install-button" onclick="jumpInstall()">全新安装</button>';
                }
            }
        })
        .catch(error => {
            const buttonView = document.querySelector('.button_view');
                    buttonView.innerHTML = '<p style="text-align:center;margin-top:30px;color:#f00;font-size:19px;">安装环境异常，请检查你建立的网站是否选择了php环境。</p><a href="../static/img/errorIMG.png" target="_blank" style="display:block;text-align:center;text-decoration:underline;margin-top:10px;">点击查看解决方法~</a>';
        });
        
        function jumpInstall() {
            location.href = 'install.html';
        }
    </script>
</body>
</html>